package wli.web.util;

import java.util.*;

public class MyDateFormat {

    // 01-Sep-02 --> 2002-09-01
    // 01-SEP-02 --> 2002-09-01
    public static String format1(String in_f1, int out_style) {

	String date  = null;
	String month = null;
	String year  = null;
	String return_string = null;

	if(in_f1.indexOf("/") !=-1) {
	    String mm   = null;
	    String dd   = null;
	    String yyyy = null;
	    int d1 =0;
	    int d2 =0;
	    d1 = in_f1.indexOf("/");
	    d2 = in_f1.lastIndexOf("/");

	    mm   = in_f1.substring(0, d1);
	    dd   = in_f1.substring(d1+1, d2);
	    yyyy = in_f1.substring(d2+1);

	    return_string = yyyy+"-"+mm+"-"+dd;
	    return return_string;
	}

	try {
	    StringTokenizer stk = new StringTokenizer(in_f1, "-");
	    while (stk.hasMoreTokens()) {
		date = stk.nextToken();
		month = stk.nextToken();
		year = stk.nextToken();
	    }

	    date = date.trim();
	    month = month.trim();
	    year = year.trim();

	    month = month.toUpperCase();
	    
	    if (month.startsWith("JAN")) {
		month = "01";
	    }
	    if (month.startsWith("FEB")) {
		month = "02";
	    }
	    if (month.startsWith("MAR")) {
		month = "03";
	    }
	    if (month.startsWith("APR")) {
		month = "04";
	    }
	    if (month.startsWith("MAY")) {
		month = "05";
	    }
	    if (month.startsWith("JUN")) {
		month = "06";
	    }
	    if (month.startsWith("JUL")) {
		month = "07";
	    }
	    if (month.startsWith("AUG")) {
		month = "08";
	    }
	    if (month.startsWith("SEP")) {
		month = "09";
	    }
	    if (month.startsWith("OCT")) {
		month = "10";
	    }
	    if (month.startsWith("NOV")) {
		month = "11";
	    }
	    if (month.startsWith("DEC")) {
		month = "12";
	    }
	    if (date.length()==1) {
		date = "0"+date;
	    }

	    if (year.length()==2) {
		year = "20"+ year;
	    }

	    if(out_style==1) {
		return_string =  year+"-"+month+"-"+date;
	    }
	}
	catch (Exception e) {
	    System.out.println("MyDataFormat:format1:Error:"+e);
	}
	return return_string;
    }
}





